// 模拟权限常量
const PERMISSION_RESOURCES = {
  USER: 'user',
  ROLE: 'role',
  PERMISSION: 'permission',
  CONFIG: 'config',
  STATS: 'stats',
  LOG: 'log',
  SYSTEM: 'system',
  ADMIN: 'admin',
  PROFILE: 'profile',
  SETTING: 'setting',
  NOTIFICATION: 'notification',
  REPORT: 'report',
  DASHBOARD: 'dashboard',
};

const PERMISSION_ACTIONS = {
  LIST: 'list',
  READ: 'read',
  CREATE: 'create',
  UPDATE: 'update',
  DELETE: 'delete',
  EXPORT: 'export',
  IMPORT: 'import',
  APPROVE: 'approve',
  REJECT: 'reject',
  PUBLISH: 'publish',
  UNPUBLISH: 'unpublish',
  ENABLE: 'enable',
  DISABLE: 'disable',
  RESET: 'reset',
  BACKUP: 'backup',
  RESTORE: 'restore',
  CONFIGURE: 'configure',
  MONITOR: 'monitor',
  ANALYZE: 'analyze',
  ACCESS: 'access',
};

const generatePermissionCode = (resource, action) => {
  return `${resource}:${action}`;
};

// 角色管理权限
const ROLE_PERMISSIONS = {
  READ: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.READ),
  CREATE: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.CREATE),
  UPDATE: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.UPDATE),
  DELETE: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.DELETE),
  ENABLE: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.ENABLE),
  DISABLE: generatePermissionCode(PERMISSION_RESOURCES.ROLE, PERMISSION_ACTIONS.DISABLE),
};

// 用户管理权限
const USER_PERMISSIONS = {
  LIST: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.LIST),
  READ: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.READ),
  CREATE: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.CREATE),
  UPDATE: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.UPDATE),
  DELETE: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.DELETE),
  ENABLE: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.ENABLE),
  DISABLE: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.DISABLE),
  RESET: generatePermissionCode(PERMISSION_RESOURCES.USER, PERMISSION_ACTIONS.RESET),
};

// 权限管理权限
const PERMISSION_PERMISSIONS = {
  READ: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.READ),
  CREATE: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.CREATE),
  UPDATE: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.UPDATE),
  DELETE: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.DELETE),
  ENABLE: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.ENABLE),
  DISABLE: generatePermissionCode(PERMISSION_RESOURCES.PERMISSION, PERMISSION_ACTIONS.DISABLE),
};

// 系统管理权限
const SYSTEM_PERMISSIONS = {
  CONFIG_READ: generatePermissionCode(PERMISSION_RESOURCES.CONFIG, PERMISSION_ACTIONS.READ),
  CONFIG_CREATE: generatePermissionCode(PERMISSION_RESOURCES.CONFIG, PERMISSION_ACTIONS.CREATE),
  CONFIG_UPDATE: generatePermissionCode(PERMISSION_RESOURCES.CONFIG, PERMISSION_ACTIONS.UPDATE),
  CONFIG_DELETE: generatePermissionCode(PERMISSION_RESOURCES.CONFIG, PERMISSION_ACTIONS.DELETE),
  CONFIG_CONFIGURE: generatePermissionCode(PERMISSION_RESOURCES.CONFIG, PERMISSION_ACTIONS.CONFIGURE),
  STATS_READ: generatePermissionCode(PERMISSION_RESOURCES.STATS, PERMISSION_ACTIONS.READ),
  STATS_ANALYZE: generatePermissionCode(PERMISSION_RESOURCES.STATS, PERMISSION_ACTIONS.ANALYZE),
  SYSTEM_MONITOR: generatePermissionCode(PERMISSION_RESOURCES.SYSTEM, PERMISSION_ACTIONS.MONITOR),
  SYSTEM_BACKUP: generatePermissionCode(PERMISSION_RESOURCES.SYSTEM, PERMISSION_ACTIONS.BACKUP),
  SYSTEM_RESTORE: generatePermissionCode(PERMISSION_RESOURCES.SYSTEM, PERMISSION_ACTIONS.RESTORE),
};

// 日志管理权限
const LOG_PERMISSIONS = {
  READ: generatePermissionCode(PERMISSION_RESOURCES.LOG, PERMISSION_ACTIONS.READ),
  DELETE: generatePermissionCode(PERMISSION_RESOURCES.LOG, PERMISSION_ACTIONS.DELETE),
  EXPORT: generatePermissionCode(PERMISSION_RESOURCES.LOG, PERMISSION_ACTIONS.EXPORT),
  ANALYZE: generatePermissionCode(PERMISSION_RESOURCES.LOG, PERMISSION_ACTIONS.ANALYZE),
  LOG_STATS_READ: generatePermissionCode(PERMISSION_RESOURCES.STATS, PERMISSION_ACTIONS.READ),
};

// 后台管理权限
const ADMIN_PERMISSIONS = {
  ACCESS: generatePermissionCode(PERMISSION_RESOURCES.ADMIN, PERMISSION_ACTIONS.ACCESS),
  DASHBOARD_READ: generatePermissionCode(PERMISSION_RESOURCES.DASHBOARD, PERMISSION_ACTIONS.READ),
  REPORT_READ: generatePermissionCode(PERMISSION_RESOURCES.REPORT, PERMISSION_ACTIONS.READ),
  REPORT_EXPORT: generatePermissionCode(PERMISSION_RESOURCES.REPORT, PERMISSION_ACTIONS.EXPORT),
  NOTIFICATION_READ: generatePermissionCode(PERMISSION_RESOURCES.NOTIFICATION, PERMISSION_ACTIONS.READ),
  NOTIFICATION_CREATE: generatePermissionCode(PERMISSION_RESOURCES.NOTIFICATION, PERMISSION_ACTIONS.CREATE),
  SETTING_READ: generatePermissionCode(PERMISSION_RESOURCES.SETTING, PERMISSION_ACTIONS.READ),
  SETTING_UPDATE: generatePermissionCode(PERMISSION_RESOURCES.SETTING, PERMISSION_ACTIONS.UPDATE),
};

// 个人权限
const PROFILE_PERMISSIONS = {
  READ: generatePermissionCode(PERMISSION_RESOURCES.PROFILE, PERMISSION_ACTIONS.READ),
  UPDATE: generatePermissionCode(PERMISSION_RESOURCES.PROFILE, PERMISSION_ACTIONS.UPDATE),
  RESET_PASSWORD: generatePermissionCode(PERMISSION_RESOURCES.PROFILE, 'reset_password'),
};

// 所有权限汇总
const ALL_PERMISSIONS = {
  ...USER_PERMISSIONS,
  ...ROLE_PERMISSIONS,
  ...PERMISSION_PERMISSIONS,
  ...SYSTEM_PERMISSIONS,
  ...LOG_PERMISSIONS,
  ...ADMIN_PERMISSIONS,
  ...PROFILE_PERMISSIONS,
};

// 模拟 PermissionUtils.getAllPermissions()
const getAllPermissions = () => {
  return Object.values(ALL_PERMISSIONS);
};

console.log('=== 测试权限生成 ===');
console.log('ROLE_PERMISSIONS:', ROLE_PERMISSIONS);
console.log('USER_PERMISSIONS:', USER_PERMISSIONS);
console.log('ALL_PERMISSIONS keys:', Object.keys(ALL_PERMISSIONS));
console.log('ALL_PERMISSIONS values:', Object.values(ALL_PERMISSIONS));

const allPermissions = getAllPermissions();
console.log('\n所有权限列表:');
allPermissions.forEach(permission => {
  console.log(`  - ${permission}`);
});

const rolePermissions = allPermissions.filter(p => p.startsWith('role:'));
console.log('\n角色相关权限:');
rolePermissions.forEach(permission => {
  console.log(`  - ${permission}`);
});

console.log(`\n总权限数: ${allPermissions.length}`);
console.log(`角色权限数: ${rolePermissions.length}`);

// 检查是否有重复的键
const keys = Object.keys(ALL_PERMISSIONS);
const uniqueKeys = [...new Set(keys)];
console.log(`\n键总数: ${keys.length}`);
console.log(`唯一键数: ${uniqueKeys.length}`);
if (keys.length !== uniqueKeys.length) {
  console.log('❌ 发现重复键！');
  const duplicates = keys.filter((key, index) => keys.indexOf(key) !== index);
  console.log('重复的键:', duplicates);
} else {
  console.log('✅ 没有重复键');
} 